<?php
include "../config/koneksi.php";
include "../class/produk.php";
include "../class/kategori.php";
include "../class/toko.php";

$Kategori_Dao = new Kategori_Dao();
$kategori=$Kategori_Dao->get_all();
$Toko_Dao = new Toko_Dao();
$toko=$Toko_Dao->get_all();

if (ISSET($_POST["input"]) && ISSET($_POST["Submit322"]) && $_POST['id_kategori']!="" && 
$_POST['id_toko']!="" && $_POST['nama_oleh2']!="" && $_POST['harga']!="" && $_POST['detil']!=""){

          $namafolder="../images/gambar_produk/";  //tempat menyimpan file
          $filename = basename ($_FILES["gambar"]["name"]);
          $file_upload = $namafolder . $filename;
          if (move_uploaded_file($_FILES["gambar"]["tmp_name"],$file_upload)){

             $produk_dao = new Produk_Dao();
				$produk=new Produk();
				$produk->id_kategori = $_POST['id_kategori'];
				$produk->id_toko = $_POST['id_toko'];
				$produk->nama_oleh2 = $_POST['nama_oleh2'];
				$produk->harga = $_POST['harga'];
				$produk->gambar = $filename;
				$produk->detil = $_POST['detil'];
				$produk_dao->add($produk);
				header("Location:index.php?menu=view_produk");
		}   
}
?>
<html>
<head>
<title>Input Produk</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body>
	<form  action="input_produk.php" method="post" enctype="multipart/form-data">
	<input type="hidden" name="input" value="form_tambah">
<table width="100%" height="30" border="0" cellpadding="0" cellspacing="0">
  <tr >
    <td height="30"> 
      <div align="left"><font size="3" face="tahoma">Tambah Produk</font><hr color=#CCCCFF></div></td>
    </tr>
  </table>
  <table width="400" border="0" align="center" bordercolor="#FF9900">
    <tr bordercolor="#FFFFFF"> 
      <td valign="top"><font size="2" face="tahoma">Kategori</font></td>
      <td valign="top"><font size="2" face="tahoma">:</font></td>
      <td valign="top"> <select name="id_kategori" id="select" ><option>===Pilih Kategori===</option>
	 <?php
     foreach($kategori as $kategori1){
     ?>
     <option value="<?php echo $kategori1->id_kategori;?>"><?php echo $kategori1->kategori;?></option>
     <?php }?>
     </select></td>
	 </tr>
    <tr bordercolor="#FFFFFF"> 
      <td valign="top"><font size="2" face="tahoma">Nama Barang</font></td>
      <td valign="top"><font size="2" face="tahoma">:</font></td>
      <td valign="top"> <input name="nama_oleh2" type="text" id="nama_oleh2" size="30"></td>
    </tr>
	<tr bordercolor="#FFFFFF"> 
      <td valign="top"><font size="2" face="tahoma">Toko</font></td>
      <td valign="top"><font size="2" face="tahoma">:</font></td>
      <td valign="top"> <select name="id_toko" type="text" id="select"><option>===Pilih Toko===</option>
	 <?php
     foreach($toko as $toko1){
     ?>
     <option value="<?php echo $toko1->id_toko;?>"><?php echo $toko1->nama_toko;?></option>
     <?php }?>
     </select></td>
    </tr>
	<tr bordercolor="#FFFFFF"> 
      <td valign="top"><font size="2" face="tahoma">Harga</font></td>
      <td valign="top"><font size="2" face="tahoma">:</font></td>
      <td valign="top"> <input name="harga" type="text" id="harga" size="30"></td>
    </tr>
    <tr bordercolor="#FFFFFF"> 
      <td valign="top"><font size="2" face="tahoma">Gambar</font></td>
      <td valign="top"><font size="2" face="tahoma">:</font></td>
      <td valign="top"> 
		<input type="file" name="gambar"  id="gambar" size="32"></td>
    </tr>
    <tr bordercolor="#FFFFFF"> 
      <td valign="top"><font size="2" face="tahoma">Detil</font></td>
      <td valign="top"><font size="2" face="tahoma">:</font></td>
      <td valign="top"> <textarea name="detil" cols="32" rows="5" id="detil"></textarea> 
      </td>
    </tr>
    <tr bordercolor="#FFFFFF"> 
      <td height="29" colspan="2"></td><td>
          <input type="submit" name="Submit322" value="Simpan">
          <button type ="button" name="fulang2" value="Batal" class="btn btn-success" onClick="javascript:history.back()">Batal
       </td>
    </tr>
  </table>
</form>
<br><br><br><br>
</body>
</html>